package com.zjcloud.jwgl.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zjcloud.common.annotation.Log;
import com.zjcloud.common.core.controller.BaseController;
import com.zjcloud.common.core.domain.AjaxResult;
import com.zjcloud.common.enums.BusinessType;
import com.zjcloud.jwgl.domain.AcLessonSchedule;
import com.zjcloud.jwgl.service.IAcLessonScheduleService;
import com.zjcloud.common.utils.poi.ExcelUtil;
import com.zjcloud.common.core.page.TableDataInfo;

/**
 * 课程安排Controller
 * 
 * @author wxl
 * @date 2024-09-13
 */
@RestController
@RequestMapping("/jwgl/schedule")
public class AcLessonScheduleController extends BaseController {
    @Autowired
    private IAcLessonScheduleService acLessonScheduleService;

    /**
     * 查询课程安排列表
     */
    // @PreAuthorize("@ss.hasPermi('jwgl:schedule:list')")
    @GetMapping("/list")
    public TableDataInfo list(AcLessonSchedule acLessonSchedule) {
        startPage();
        List<AcLessonSchedule> list = acLessonScheduleService.selectAcLessonScheduleList(acLessonSchedule);
        return getDataTable(list);
    }

    /**
     * 导出课程安排列表
     */
    // @PreAuthorize("@ss.hasPermi('jwgl:schedule:export')")
    @Log(title = "课程安排", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AcLessonSchedule acLessonSchedule) {
        List<AcLessonSchedule> list = acLessonScheduleService.selectAcLessonScheduleList(acLessonSchedule);
        ExcelUtil<AcLessonSchedule> util = new ExcelUtil<AcLessonSchedule>(AcLessonSchedule.class);
        util.exportExcel(response, list, "课程安排数据");
    }

    /**
     * 获取课程安排详细信息
     */
    // @PreAuthorize("@ss.hasPermi('jwgl:schedule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(acLessonScheduleService.selectAcLessonScheduleById(id));
    }

    /**
     * 新增课程安排
     */
    // @PreAuthorize("@ss.hasPermi('jwgl:schedule:add')")
    @Log(title = "课程安排", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AcLessonSchedule acLessonSchedule) {
        return toAjax(acLessonScheduleService.insertAcLessonSchedule(acLessonSchedule));
    }

    /**
     * 修改课程安排
     */
    // @PreAuthorize("@ss.hasPermi('jwgl:schedule:edit')")
    @Log(title = "课程安排", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AcLessonSchedule acLessonSchedule) {
        return toAjax(acLessonScheduleService.updateAcLessonSchedule(acLessonSchedule));
    }

    /**
     * 删除课程安排
     */
    // @PreAuthorize("@ss.hasPermi('jwgl:schedule:remove')")
    @Log(title = "课程安排", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(acLessonScheduleService.deleteAcLessonScheduleByIds(ids));
    }

    /**
     * 智能排课
     */
    // @PreAuthorize("@ss.hasPermi('jwgl:schedule:generate')")
    @Log(title = "智能排课", businessType = BusinessType.OTHER)
    @PostMapping("/generate")
    public AjaxResult generateSchedule(@RequestBody Map<String, Object> params) {
        return success(acLessonScheduleService.generateSchedule(params));
    }

    /**
     * 检测课程冲突
     */
    // @PreAuthorize("@ss.hasPermi('jwgl:schedule:check')")
    @PostMapping("/check")
    public AjaxResult checkConflict(@RequestBody AcLessonSchedule acLessonSchedule) {
        return success(acLessonScheduleService.checkConflict(acLessonSchedule));
    }
}